package com.guo.config;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

public class AjaxResult {
    private Object data;
    private Boolean success;
    private String msg;
    //得到自己的对象
    public static AjaxResult me(){
        return new AjaxResult();
    }
    //如果传递msg，则默认为失败
    public static AjaxResult me(String msg){
        return new AjaxResult(false,msg);
    }
    //如果传递data，则默认为成功
    public static AjaxResult me(Object data){
        return new AjaxResult(true,data);
    }

    public AjaxResult() {
        this.success = true;
    }
    public AjaxResult(Boolean success, Object data) {
        this.success = success;
        this.data = data;
    }
    public AjaxResult(Boolean success, String msg) {
        this.success = success;
        this.msg = msg;
    }
    public AjaxResult(Object data, Boolean success, String msg) {
        this.data = data;
        this.success = success;
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public AjaxResult setData(Object data) {
        this.data = data;
        return this;
    }

    public Boolean getSuccess() {
        return success;
    }

    public AjaxResult setSuccess(Boolean success) {
        this.success = success;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public AjaxResult setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    @Override
    public String toString() {
        return "AjaxResult{" +
                "data=" + data +
                ", success=" + success +
                ", msg='" + msg + '\'' +
                '}';
    }
}
